<?php

/*
 * @author Ebrain Cedeno <ebraincedeno@gmail.com>
 */
class TForm extends TWidget{
    
    public $Name='';
    public $Id='';
    public $Method = "GET";
    public $Action = '#';
    public $OptionHtmlAditional = array();
    public static $ValueMessageError = array();
    public static $ValueMessageOther = array();
    
    public function __construct() {
        parent::__construct();
    }
    
    public function startForm(){
        
        $startForm = '<form name="'.$this->Name.'" id="'.$this->Id.'" '.$this->getOptionsAditional().' method="'.$this->Method.'" action="'.$this->Action.'">';
        return $startForm;
    }
    
    public function endForm(){
        return '</form>';
    }
    
    public static function addMessage($name,$message){
        self::$ValueMessageOther[$name] = $message;
    }
    
    public static function addMessageError($name,$message){
        self::$ValueMessageError[$name] = $message;
    }
    
    public function showMessageOther($name){
        if (count(self::$ValueMessageOther) > 0){
            if (array_key_exists($name, self::$ValueMessageOther)){

                return '<div style="position:border:1px solid gray;background-color:#FFFDD0; height:'.$this->Height.'px;">
                                    <table width="100%" border="0" bgcolor="#FFFDD0">
                                        <tr>
                                            <td align="right" style="width:16px;"><img src="'.VeCms::getPathImage().'/accepted.png" width="16" height="16" /></td>
                                            <td style="font-weight:bold;">
                                                '.self::$ValueMessageOther[$name].'
                                            </td>
                                        </tr>
                                    </table>
                                </div>';
                
                unset(self::$ValueMessageOther[$name]);
            }
            
        }
    }
    
    public function showMessageError($fielname = null){
        
        if (count(self::$ValueMessageError) > 0){
            if (!is_null($fielname)){    
                if (array_key_exists($fielname, self::$ValueMessageError)){
                    return '<div style="border:1px solid gray;background-color:#FFFDD0; height:'.$this->Height.'px;">
                                <table width="100%" border="0" bgcolor="#FFFDD0">
                                    <tr>
                                        <td align="right" style="width:16px;"><img src="'.VeCms::getPathImage().'/error.png" width="16" height="16" /></td>
                                        <td style="color:red; font-weight:bold;">
                                            '.self::$ValueMessageError[$fielname].'
                                        </td>
                                    </tr>
                                </table>
                            </div>';
                    unset(self::$ValueMessageError[$fielname]);
                }
            }
        }    
    }
}
?>
